#pragma once

#include <MyFC/Container.h>
#include <MyFC/Timer.h>
#include <MyFC/Glyph.h>
#include <MyFC/Timer.h>	 
#include <MyFC/ScrollBar.h>	 

#include "SegmentSet.h"
#include "SegmentControl.h"
#include "DLL.h"

#include <vector>

namespace My {

const int RowHeight			= 14;
const int DividerHeight		= 4;

class Timeline;

class DLL_API SegmentList : public Widget, public Container
{
private:
	class Animator : public Timer {
	private:
		SegmentList &		m_Owner;
	public:
		Animator(SegmentList & owner) : m_Owner(owner) { }
	public:
		virtual void OnTimer();
	};
	friend class SegmentControl;
	friend class SegmentControl::LeftBracket;
	friend class SegmentControl::RightBracket;
	friend class Animator;
private:
	Timeline &				m_Timeline;
	SegmentSet *			m_pSegments;
	SegmentControlVector	m_Segments;
	SegmentControlList		m_Animated;
	Animator				m_Animator;
	SysColorGlyph			m_Left;
	SysColorGlyph			m_Right;
	SysColorGlyph			m_Mask;
	SysColorGlyph			m_MaskPressed;
	SysColorGlyph			m_MaskGrayed;
	CBitmap					m_DarkOrangeRipple;
	CBitmap					m_LightOrangeRipple;
	CBitmap					m_DarkBlueRipple;
	CBitmap					m_LightBlueRipple;
	CBitmap					m_DarkGreenRipple;
	CBitmap					m_LightGreenRipple;
	int						m_InsertionSource;
	int						m_Insertion;
	int						m_InsertionY;
	bool					m_InsertionVisible;
	bool					m_ShowInsertion;
	Timer					m_AutoScroll;
	ScrollBar				m_VScrollBar;
	int						m_VOffset;
	int						m_VRange;
	int						m_VPage;
	int						m_VAutoScroll;
	int						m_Gap;
private:
	void SetVOffset(int offset);
	void UpdateVOffset()
		{ SetVOffset(m_VOffset); }
	void UpdateVRange();
	void UpdateVPage();
	void UpdateVScrollBar();
	void SetVAutoScroll(int d);
	void OnAutoScroll(bool mouseMove = true);
public:
	virtual int GetVOffset()
		{ return m_VOffset; }
	virtual int GetVRange()
		{ return m_VRange; }
	virtual int GetVPage()
		{ return m_VPage; }
private:
	int TimeToClient(double time);
	double ClientToTime(int x);
	void UpdateAnimation();
	int GetInsertionY(int pos);
	void ShowInsertion(); 
	void HideInsertion(); 
	bool DrawInsertion();
	void RedrawInsertion();
	void Insertion(int pos);
public:
	virtual String Hint() const 
		{ return "Segments"; }
public:
	SegmentList(Timeline &);
	~SegmentList();
public:
	SegmentSet * GetSegments() const 
		{ return m_pSegments; }
	void SetSegments(SegmentSet *);
	void UpdateSegments();
protected:
	virtual void ProcessEvent(My::Event &);
	virtual void Paint(CDC * pDC, const CRect & r);
	virtual void HandleLeftDown(unsigned int flags, const CPoint & p);
	virtual void HandleResize(int sx, int sy);
public:
	CBitmap	m_Alternate;
};

} // My